package com.hehao.java_basic.stream;


import com.hehao.common.entiy.Person;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author Damon
 * @date 2022/2/23
 * stream 流两种流形式：顺序流和并行流的创建区分
 */
public class StreamCreateDemo {
    public static void main(String[] args) {
        //of创建
        Stream<Integer> ofStream = Stream.of(1, 2, 3, 5);
        //iterate创建步长规律的stream
        Stream.iterate(0, x -> x + 2).limit(2).forEach(System.out::println);
        //generate
        Stream.generate(Math::random).limit(2).forEach(System.out::println);


        //Stream流转并行流
        List<Person> persons = Person.getList();
        Optional<Person> first = persons.stream().parallel().filter(o -> o.getSalary() > 8000).findFirst();
        first.ifPresent(System.out::println);

    }

}
